export default {
    showToast: function (title = '', duration) {
        uni.showToast({
            title: title,
            icon: 'none',
            duration: duration ? duration : 3000
        });
    },
    /* 成功 */
    showSuccess: function (title, mask = true, duration = 3000) {
        uni.showToast({
            title: title,
            mask: mask,
            icon: 'success',
            duration: duration
        });
    },
    /* 警告 */
    showWarning: function (title, duration = 3000) {
        uni.showToast({
            title: title,
            icon: 'fail',
            duration: duration
        });
    },
    /* 错误 */
    showError: function (title, mask = false, duration = 3000) {
        uni.showToast({
            title: title,
            mask: mask,
            icon: 'error',
            duration: duration
        });
    },
    /* 加载 */
    showLoading: function (title = '正在加载...', mask = true) {
        uni.showLoading({
            title: title,
            icon: 'loading',
            mask: mask
        });
    },
    /* 隐藏加载 */
    hideLoading: function () {
        uni.hideLoading();
    },
    /* 显示模态窗口 */
    showModal: function (title = null, content = null, showCancel = true) {
        return new Promise((resolve, reject) => {
            uni.showModal({
                title: title ? title : '温馨提示',
                content: content || '',
                showCancel: showCancel,
                success: (res) => {
                    if (res.confirm) {
                        resolve(true);
                    } else if (res.cancel) {
                        resolve(false);
                    }
                },
                fail: (err) => {
                    reject(err);
                }
            });
        });
    }
};